//
//  AppDelegate.swift
//  Keyboard
//
//  Created by xinglian on 2022/12/15.
//

import UIKit
let UMKey = "6482d5bfe31d6071ec4db721"
let PgyAPPKey = "0ffb62b76f420650eeb70eff7f891050"
var APP : AppDelegate = UIApplication.shared.delegate as! AppDelegate
let updateNote = NSNotification.Name("updateNote")
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window : UIWindow?
    var logwindow = Logwindow.share
    var language = ""
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        localLanguage()
        setupSDK()
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = CCNavigationController(rootViewController:HomeViewController())
        self.window?.makeKeyAndVisible()
        return true
    }
    
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        localLanguage()
    }
    
    func localLanguage(){
        let languages = NSLocale.preferredLanguages
        if languages.count > 0 {
            let code = languages.first!
            if code.hasPrefix("en"){
                self.language = "en"
            }else if code.hasPrefix("zh"){
                self.language = "zh"
            }else{
                self.language = "en"
            }
        }else{
            self.language = "en"
        }
        BleDataTool.share.setupConfig()
    }
    
}

//MARK: - 设置一些sdk
extension AppDelegate{
    
    func setupSDK(){
        setupPgy()
        setupUMCommon()
    }
    
    ///设置蒲公英SDK
    private func setupPgy(){
//        ///启动基本SDK
//        PgyManager.shared().isFeedbackEnabled = false
//        PgyManager.shared().start(withAppId:PgyAPPKey)
//        ///启动更新检查SDK
//        PgyUpdateManager.sharedPgy().start(withAppId: PgyAPPKey)
//        PgyUpdateManager.sharedPgy().checkUpdate()
    }
    
    private func setupUMCommon(){
        UMConfigure.setLogEnabled(false)
        UMConfigure.initWithAppkey(UMKey, channel: "App Store")
    }
}
